<template>
  <div>
    <el-card>
      <el-row>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item><a href="#">问诊管理</a></el-breadcrumb-item>
          <el-breadcrumb-item>在线问诊消息列表</el-breadcrumb-item>
        </el-breadcrumb>
      </el-row>
      <el-skeleton :rows="6" animated :loading="loading"/>
      <el-empty description="暂无数据" v-if="offlineList.length==0"></el-empty>
      <el-table :data="offlineList" stripe style="width: 100%" v-if="offlineList.length!=0">
        <el-table-column prop="name" label="姓名"> </el-table-column>
        <el-table-column prop="age" label="年龄"> </el-table-column>
        <el-table-column prop="sex" label="性别"> </el-table-column>
        <el-table-column prop="phone" label="手机"> </el-table-column>
        <el-table-column prop="message" label="预约内容" width="300px">
        </el-table-column>
        <el-table-column prop="orderDate" label="预约日期" width="200px">
        </el-table-column>
        <el-table-column prop="address" label="上门地址" width="200px">
        </el-table-column>
        <el-table-column label="当前状态">
          <template slot-scope="scope">
            <el-tag
              v-if="scope.row.offlineDate === null"
              size="mini"
              type="danger"
              >未处理</el-tag
            >
            <el-tag v-else size="mini" type="success">已处理</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="medium"
              @click="showEditDialog(scope.row.id)"
              >查看或处理</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[100, 200, 300, 400]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
      >
      </el-pagination> -->
    </el-card>
    <el-dialog
      title="预约就诊时间"
      :visible.sync="editDialogVisibal"
      width="30%"
    >
      <el-form ref="form" :model="editForm" label-width="120px">
        <el-form-item label="安排就诊时间">
          <el-date-picker
            v-model="editForm.offlineDate"
            type="datetime"
            placeholder="选择日期时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-switch v-model="editForm.status" active-text="已完成" inactive-text="未完成" :active-value="1" :inactive-value="0">
          </el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisibal = false">取 消</el-button>
        <el-button type="primary" @click="editConfirm"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      offlineList: [],
      doctorID: window.sessionStorage.getItem("doctorID"),
      editDialogVisibal: false,
      editForm: {
      },
      loading:false
    };
  },
  created() {
    this.getOfflineList();
  },
  methods: {
    async getOfflineList() {
      const { data: res } = await this.$http.get(
        "/api/offline/offlineList/" + this.doctorID
      );
      this.offlineList = res.offlineList;
      this.loading=false
    },
    async showEditDialog(id) {
      const { data: res } = await this.$http.get("/api/offline/info/" + id);
      console.log(res);
      if (res.status !== 200) return this.$message.error("获取信息失败");
      this.editForm = res.info;
      this.editDialogVisibal = true;
    },
    async editConfirm(){
      const { data : res } = await this.$http.post('/api/offline/edit/' + this.editForm._id ,this.editForm)
      if(res.status !== 200) return  this.$message.error('操作失败')
      this.editDialogVisibal = false
      this.$message.success('操作成功')
      this.getOfflineList()
    }
  },
};
</script>

<style scoped>
.avator {
  width: 50px;
  height: 50px;
  border: 1px solid lightblue;
}
.el-tag {
  margin: 0 5px;
}
.el-pagination {
  margin-top: 20px;
}
</style>
